package com.JobFind.controller;

import java.io.PrintWriter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.aspectj.weaver.patterns.ThisOrTargetAnnotationPointcut;

import com.opensymphony.xwork2.ActionSupport;
import com.JobFind.logic.ILogLogic;
import com.JobFind.logic.IUserLogic;
import com.JobFind.DTO.BringDataDTO;
import com.JobFind.DTO.UserDTO;

public class UserController extends BaseAction {

	private static final long serialVersionUID = 1L;
	private IUserLogic userLogic;
	private ILogLogic logLogic;
	private UserDTO userDTO;
	private BringDataDTO dateDTO;
	
	public IUserLogic getUserLogic() {
		return userLogic;
	}
	@Resource
	public void setUserLogic(IUserLogic userLogic) {
		this.userLogic = userLogic;
	}
	public UserDTO getUserDTO() {
		return userDTO;
	}
	
	public ILogLogic getLogLogic() {
		return logLogic;
	}
	@Resource
	public void setLogLogic(ILogLogic logLogic) {
		this.logLogic = logLogic;
	}
	public void setUserDTO(UserDTO userDTO) {
		this.userDTO = userDTO;
	}
    
	public BringDataDTO getDateDTO() {
		return dateDTO;
	}
	public void setDateDTO(BringDataDTO dateDTO) {
		this.dateDTO = dateDTO;
	}
	public void loginCheck() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.userLogic.loginCheck(userDTO.getUserLoginName(), userDTO.getUserPwd()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	public void getUserSession () throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.userLogic.getUserSession());
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	public void getUserInfoById() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.userLogic.getUserInfoById(userDTO.getUserId()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void logoutCheck() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.userLogic.logoutCheck());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void updateUserInfo() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.userLogic.updateUserInfo(userDTO.getUserId(),userDTO.getHomePlace(), userDTO.getUserBirthday(), userDTO.getUserNickName(), userDTO.getUserNation()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void modifyUserPwd() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.userLogic.modifyUserPwd(userDTO.getUserId(), userDTO.getUserPwd()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}

	public void regCheck() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.userLogic.addUser(userDTO));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void getAllUncheckUser() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.userLogic.getAllUncheckUser());
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void checkUserInfo() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.userLogic.checkUserInfo(userDTO.getUserId(),userDTO.getUserStatus()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void getSimplyUserInfoById() throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.userLogic.getSimplyUserInfoById(userDTO.getUserId()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
	
	public void getLogInfo()throws Exception{
		PrintWriter out = getWriter();
		try {
			out.println(this.logLogic.getLogInfo(dateDTO.getStartTime(), dateDTO.getEndTime()));
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			out.flush();
			out.close();
		}
	}
}
